<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>注册</title>
    <link rel="stylesheet" type="text/css" href="css/public.css"/>
    <link rel="stylesheet" type="text/css" href="css/login.css"/>
</head>
<body><!-------------------reg-------------------------->
<div class="reg">
    <form onsubmit="return false"  ><h1><a href="/index"><img src="img/temp/logo.png"></a></h1>
        <p>用户注册</p>
        <p><input type="text"  name="username" class="" id="username" value="" placeholder="请输入用户名" required></p>
        <p><input type="text" name="password" value="" id="password" placeholder="请输入密码" required></p>
        <p><input type="text" name="password2" value="" id="password2" placeholder="请确认密码" required></p>
        <p class="txtL txt"><input class="code" type="text" id="code" name="code" value="" placeholder="验证码" required><img
               title="看不清，点击切换" style="margin-top: -10px;margin-left: 20px" onclick="qh()" id="img" src="/cpacha?type=regCpacha"></p>
        <p><input type="submit" name="" onclick="reg()" value="注册"></p>
        <p class="txtL txt">完成此注册，即表明您同意了我们的<a href="#">
            使用条款和隐私策略
        </a></p>
        <p class="txt"><a href="/login"><span></span>已有账号登录</a></p>
        <!--<a href="#" class="off"><img src="img/temp/off.png"></a>--></form>
</div>
<script src="js/jquery-1.12.4.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/sweetalert.js"> </script>

<script>
    function qh() {
        $("#img").attr("src","/cpacha?cpachaType=regCpacha&data="+new Date())
    }

    function reg() {
        var password = $("#password").val();
        var password2 = $("#password2").val();
        var username = $("#username").val();
        var code = $("#code").val();
        if (password.length<=0 || password2.length<=0 || username.length<=0 || code.length<=0){
           return;
        }
       if (password!=password2){
           swal("OMG!", "两次密码输入不一样！！", "error")
           return;
       }
       $.post("user/reg",{password,username,code},function (result) {
           console.log(result)
           if (result.state=='error'){
               swal("OMG!", result.msg+"！！", "error")
               $("#img").attr("src","/cpacha?type=regCpacha&data="+new Date())
           }else{
               window.location.replace("login")
           }

       })

    }

</script>
</body>
</html>